package com.eliza.notice.activity

import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.eliza.notice.R


class ToastActivity : AppCompatActivity() {
    var context = this

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_toast);

        /**
         * Android 11下， Toast自定义被限制
         *
         */
        val toast = Toast.makeText(context, "吐司提示文本信息", Toast.LENGTH_SHORT).apply {
            setGravity(Gravity.CENTER_VERTICAL, 0, 0)//设置Toast显示的位置
        }
        val image = ImageView(this).apply {
            setImageResource(R.mipmap.ic_launcher_round)
        }

        //自定义toast布局
        val layout = toast.view as LinearLayout

        layout.findViewById<TextView>(android.R.id.message).apply {
            setTextColor(Color.GRAY)
        }

        layout.setBackgroundColor(Color.BLUE)
        layout.addView(image, 0)

        findViewById<Button>(R.id.toast_btn).setOnClickListener {
            toast.show();
        }
    }

}
